import GCJ_CLASS_TYPE = require('./../../common/GCJ_CLASS_TYPE');
import FColorBase = require('./FColorBase');
var CONFIG=require('../../../../common/config');
export  = FColor;

/**
 *
 * @author 
 *
 */
class FColor extends FColorBase{
    public r: number = 0;// 0-255
    public g: number = 0;// 0-255
    public b: number = 0;// 0-255
    
    public static DEFAULT_COLOR: Array<Array<number>>=[
        [150,0,0],
        [100,0,0],
        [50,0,0],
        [0,150,0],
        [0,100,0],
        [0,50,0],
        [0,0,150],
        [0,0,100],
        [0,0,50],
        
        [150,50,0],
        [100,50,0],
        [50,50,0],
        [150,100,0],
        [100,100,0],
        [50,100,0],
        [150,150,0],
        [100,150,0],
        [50,150,0],
        
        [150,0,50],
        [100,0,50],
        [50,0,50],
        [150,0,100],
        [100,0,100],
        [50,0,100],
        [150,0,150],
        [100,0,150],
        [50,0,150],
        
        [50,150,0],
        [50,100,0],
        [50,50,0],
        [100,150,0],
        [100,100,0],
        [100,50,0],
        [150,150,0],
        [150,100,0],
        [150,50,0],
    ];
    
	public constructor() {
        super();
        
        this.ct = GCJ_CLASS_TYPE.CLASS_TYPE_FColor;
	}
	// 创建
	public static from(r,g,b):FColor{
        var ret: FColor=new FColor();
        ret.r=r;
        ret.g=g;
        ret.b=b;
        return ret;
	}
	
	// 随机创建颜色
	public static randomColor():FColor{
        var index:number = Math.ceil(Math.random()*FColor.DEFAULT_COLOR.length)%FColor.DEFAULT_COLOR.length;
        var ret: FColor=new FColor();
        ret.r=FColor.DEFAULT_COLOR[index][0];
        ret.g=FColor.DEFAULT_COLOR[index][1];
        ret.b=FColor.DEFAULT_COLOR[index][2];
        return ret;
	}
	// 黑色
	public static blackColor():FColor{
        var ret: FColor=new FColor();
        return ret;
	}
    // 白色
    public static whiteColor(): FColor {
        var ret: FColor=new FColor();
        ret.r=255;
        ret.g=255;
        ret.b=255;
        return ret;
    }
    // 淡灰色
    public static lightGrayColor(): FColor {
        var ret: FColor=new FColor();
        ret.r=100;
        ret.g=100;
        ret.b=100;
        return ret;
    }
    // 橙色
    public static orangeColor(): FColor {
        var ret: FColor=new FColor();
        ret.r=230;
        ret.g=121;
        ret.b=90;
        return ret;
    }
	
    // 从json对象(注意不是json字符串)中解析
    public fromJson(jsonObj, versionId) { 
        super.fromJson(jsonObj,versionId);
        
        this.r = jsonObj.r;
        this.g = jsonObj.g;
        this.b = jsonObj.b;
    }
    // 转成json字符串
    public toJson():string {
        // 去掉父json字符串的头尾
        var superJson = super.toJson();
        superJson = superJson.substr(1,superJson.length-2);
        
        var ret = '{';
        ret +=superJson;
        
        // r
        ret +=',';
        ret += '"r":';
        ret += this.r;
        // g
        ret +=',';
        ret += '"g":';
        ret += this.g;
        // b
        ret +=',';
        ret += '"b":';
        ret += this.b;
        
        ret+='}';
        return ret;
    }
    /**
    * 复制自身
    */
    public deepCloneObject(): any{
        var ret: FColor=new FColor();
        ret.fromJson(JSON.parse(this.toJson()),0);
        return ret;
    }
    /**
    * 复制自身
    */
    public copy(): any {
        return this.deepCloneObject();
    }
    
    /**
     * RGB转换成数字
     */ 
    public toHex():number{
        return this.r*256*256+this.g*256+this.b; 
    }
//SJG_MARK_APPEND--------------------


}//SJG_MARK_END-------------------------